﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Windows.Data;

namespace WyoCode.WyoApp_VSTools
{
    [ContentProperty("Child")]
    public partial class WCLabel : UserControl
    {


        Grid root;
        TextBlock label;
        Border childBorder;





        public string LabelText
        {
            get { return (string)GetValue(LabelTextProperty); }
            set { SetValue(LabelTextProperty, value); }
        }

        // Using a DependencyProperty as the backing store for LabelText.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty LabelTextProperty =
            DependencyProperty.Register("LabelText", typeof(string), typeof(WCLabel), new PropertyMetadata(null));




        public double LabelWidth
        {
            get { return (double)GetValue(LabelWidthProperty); }
            set { SetValue(LabelWidthProperty, value); }
        }

        // Using a DependencyProperty as the backing store for LabelWidth.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty LabelWidthProperty =
            DependencyProperty.Register("LabelWidth", typeof(double), typeof(WCLabel), new PropertyMetadata(null));




        public UIElement Child
        {
            get { return (UIElement)GetValue(ChildProperty); }
            set
            {
                SetValue(ChildProperty, value);
                this.childBorder.Child = value;
            }
        }

        // Using a DependencyProperty as the backing store for Child.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ChildProperty =
            DependencyProperty.Register("Child", typeof(UIElement), typeof(WCLabel), new PropertyMetadata(null));





        public WCLabel()
        {


            label = new TextBlock()
            {
                Margin = new Thickness(2, 0, 0, 0),
                HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
                VerticalAlignment = System.Windows.VerticalAlignment.Center,
                MinWidth = 100
            };

            this.label.SetBinding(TextBlock.TextProperty, new Binding("LabelText") { Source = this, Mode = BindingMode.TwoWay });
            this.label.SetBinding(TextBlock.WidthProperty, new Binding("LabelWidth") { Source = this, Mode = BindingMode.TwoWay });


            childBorder = new Border()
            {
                HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
                VerticalAlignment = System.Windows.VerticalAlignment.Center
            };



            root = new Grid();
            root.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
            root.ColumnDefinitions.Add(new ColumnDefinition());

            root.Children.Add(label);
            root.Children.Add(childBorder);
            Grid.SetColumn(label, 0);
            Grid.SetColumn(childBorder, 1);

            this.Content = root;
        }


    }
}
